package org.magicbox.qjunTPO;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl;
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;

import javax.sql.DataSource;

@SpringBootApplication
@EnableGlobalMethodSecurity(securedEnabled = true,prePostEnabled = true)      //想要使用注解控制角色首先要在这里允许,这两个是不同的方式 但是不冲突
public class QjunTpoApplication {

	public static void main(String[] args) {
		SpringApplication.run(QjunTpoApplication.class, args);
	}
	@Autowired
	private DataSource dataSource;

	@Bean
	public PersistentTokenRepository getPersistentTokenRepository(){
		JdbcTokenRepositoryImpl jdbcTokenRepository = new JdbcTokenRepositoryImpl();
		jdbcTokenRepository.setDataSource(dataSource);
		//当启动时自动建表,第二次启动一定要注释掉
//        jdbcTokenRepository.setCreateTableOnStartup(true);
		return  jdbcTokenRepository;
	}

//	################
//	@Override
//	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
//		return builder.sources(QjunTpoApplication.class);
//	}
//	##################
}
